﻿/*
 *  Author: Louis A. Leskoviansky
 *  Company: Artemis Solutions Group (http://www.artemis-solutions.com)
 */


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;
using System.Web.Script;
using System.Web.Script.Serialization;

namespace AjaxControlFramework
{
    public class ExceptionJavascriptConverter : JavaScriptConverter
    {
        //------// Properties \\--------------------------------------------\\
        public override IEnumerable<Type> SupportedTypes
        {
            get { return new List<Type>(new Type[] { typeof(System.Exception) }); }
        }
        //------\\ Properties //--------------------------------------------//



        //------// Methods \\-----------------------------------------------\\
        public override IDictionary<string, object> Serialize(object obj, JavaScriptSerializer serializer)
        {
            System.Exception exception = (System.Exception)obj;

            IDictionary<string, object> jsObject = new Dictionary<string, object>();
            jsObject.Add("Message", exception.Message);
            jsObject.Add("Source", exception.Source);
            jsObject.Add("StackTrace", exception.StackTrace);

            return jsObject;
        }


        public override object Deserialize(IDictionary<string, object> dictionary, Type type, JavaScriptSerializer serializer)
        {
            throw new NotImplementedException();
        }
        //------\\ Methods //-----------------------------------------------//
    }
}
